import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

public class Task6_1 {
    public static void main(String[] args) throws IOException {

        FileOutputStream fos=new FileOutputStream("example.txt");
        String s="我爱java";
        byte[] b=s.getBytes();
        fos.write(b);
        fos.close();




         FileInputStream fis=new FileInputStream("example.txt");

     byte[] bys=new byte[1024];
     int len=0;
       while ((len=fis.read(bys))!=-1){
           String s1=new String(bys,0,len);
           System.out.println(s1);
       }
       fis.close();


       //网文件追加数据
        FileOutputStream fos2=new FileOutputStream("example.txt",true);
    String s2="\r\n九日海是个gay";
    fos2.write(s2.getBytes());
    fos2.close();
    FileInputStream fis2=new FileInputStream("example.txt");
    byte[] bys2=new byte[1024];
    int len2=0;
    while ((len2=fis2.read(bys2))!=-1){
        System.out.println(new String(bys2,0,len2));
    }
    fis2.close();
    }
}
